<?php defined("SYSPATH") or die("No direct script access.");

class Session_Basket_Core {

	private $cart;

	function __construct($cart="") {
		$this->cart = $cart;
	}

	function getCart() {
		return $this->cart;
	}

	function addToCart($item) {
		if(isset($this->cart[$item])) {
			$this->cart[$item]++;
		} else {
			$this->cart[$item] = 1;
		}
	}

	function deleteFromCart($item) {
		if(isset($this->cart[$item])) {
			$this->cart[$item]--;
			if($this->cart[$item] == 0) {
				unset($this->cart[$item]);
			}
		}
	}

}

$items = $_SESSION["cart"];

// Retrieve the parameters
$task = $_GET['task'];
$item = $_GET['item'];

if ($task == "add") {

	$cart->addToCart($item);
	$_SESSION["cart"] = $cart->getCart();
	echo "item added!";

} else {

	$cart->deleteFromCart($item);
	echo "item deleted!";

}
?>

